<!-- /*
 * @Author: FengKongLi 
 * @Date: 2021-09-17 14:43:01 
 * @Last Modified by: FengKongLi
 * @Last Modified time: 2021-09-17 16:19:57
 */-->
<template>
  <div>
    <!-- 头部 -->
    <Head></Head>
    <!-- 内容区域 -->
    <div class="contentContainer">
      <div class="wrapper">
        <!-- 轮播图 -->
        <div class="swiper">
          <el-carousel height="400px">
            <el-carousel-item v-for="item in swiperList" :key="item.id">
              <el-image :src="item.url" fit="cover"></el-image>
            </el-carousel-item>
          </el-carousel>
        </div>
        <!-- 新闻区域 -->
        <div class="new-box">
          <div
            class="newBoxItem"
            v-for="(item, index) in ArticlesList"
            :key="index"
          >
            <div class="title">
              <div class="notify">
                <div>{{ item.category.name }}</div>
              </div>
              <div class="more">
                <div @click="toMore">更多>></div>
              </div>
            </div>
            <div class="contentBox" v-if="item.aritcle.length > 0">
              <ul class="contentItem">
                <li
                  v-for="item in item.aritcle"
                  :key="item.id"
                  @click="toDetail(item.id)"
                >
                  <div class="time">{{ item.publishTime | fmtDate }}</div>
                  <div class="Title">{{ item.title }}</div>
                </li>
              </ul>
            </div>
            <div v-else>暂无数据</div>
          </div>
        </div>
        <!-- 重要新闻展示 -->
        <div class="major-news-box"></div>
      </div>
    </div>
    <!-- 底部 -->
    <Foot></Foot>
  </div>
</template>

<script>
import { carouselFindAll, findCategoryArticles } from "../api/home/home";
import Head from "./components/Head.vue";
import Foot from "./components/Foot.vue";
export default {
  data() {
    return {
      // 轮播图数据
      swiperList: [],
      // 新闻区域数据
      ArticlesList: [],
    };
  },
  components: {
    Head,
    Foot,
  },
  created() {
    this.getSwiperData();
    this.getcategroyArticlesListData();
  },
  methods: {
    async getSwiperData() {
      let res = await carouselFindAll();
      // console.log(res.data);
      this.swiperList = res.data;
    },
    async getcategroyArticlesListData() {
      let res = await findCategoryArticles();
      // console.log(res.data);
      this.ArticlesList = res.data;
    },
    toMore() {
      this.$router.push({ path: "/list" });
    },
    toDetail(id) {
      this.$router.push({
        path: "/articleDetail",
        query: {
          id: id,
        },
      });
    },
    
  },
};
</script>

<style lang="scss" scoped>
@import "../assets/home.scss";
</style>